import Vue from 'vue'
import Vuex from 'vuex'
import {userinfo} from '@/api/http'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:'',
    userinfo:{},
    stateMenu:{},
  },
  getters: {
    nickname: state => state.userinfo.nickname,
   username: state => state.userinfo.username,
    user_pic: state => state.userinfo.user_pic,
    email: state => state.userinfo.email,
  },
  mutations: {
    setToken (state,val) {
      state.token = val
    },
    getuserinfo (state,val) {
      state.userinfo = val
    },
    getstateMenu(state,val){
      state.stateMenu=val
    }
  },
  actions: {
    async   getuserinfo (store) {
      const res = await userinfo()
      console.log(res)
      console.log(res.data.data)
      if(res.data.code ===0){
      store.commit('getuserinfo',res.data.data)
      console.log('getuserinfo',res.data.data)
      }
      
    
  },
  },
  modules: {
  }
})
